package indi.zhifa.recipe.bailan.framework.auth.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import indi.zhifa.recipe.bailan.framework.auth.dao.mapper.RelUserDepMapper;
import indi.zhifa.recipe.bailan.framework.auth.dao.service.IRelUserDepDbService;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.RelUserAuthEntity;
import indi.zhifa.recipe.bailan.framework.mysql.entity.annotations.ZfDbService;
import indi.zhifa.recipe.bailan.framework.mysql.service.impl.ZfDbServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

@ZfDbService(name = "RelUserAuthEntity")
public class RelUserDepDbServiceImpl extends ZfDbServiceImpl<RelUserDepMapper, RelUserAuthEntity> implements IRelUserDepDbService {

    @Cacheable(value = "sys_rel_user_dep-listByUserId",key = "#pUserId",condition = "#result!=null")
    @Override
    public List<RelUserAuthEntity> listByUserId(Long pUserId) {
        LambdaQueryWrapper<RelUserAuthEntity> queryWrapper = Wrappers.<RelUserAuthEntity>lambdaQuery()
                .eq(RelUserAuthEntity::getUserId,pUserId);
        return list(queryWrapper);
    }

    @CachePut(value = "sys_rel_user_dep-listByUserId",key = "#pUserId")
    @Override
    public List<RelUserAuthEntity> saveBatch(Long pUserId, List<RelUserAuthEntity> pRelUserAuthEntityList) {
        saveBatch(pRelUserAuthEntityList);
        return pRelUserAuthEntityList;
    }

    @CacheEvict(value = "sys_rel_user_dep-listByUserId",key = "#pUserId")
    @Override
    public void deleteByUserId(Long pUserId) {
        LambdaUpdateWrapper<RelUserAuthEntity> queryWrapper = Wrappers.<RelUserAuthEntity>lambdaUpdate()
                .eq(RelUserAuthEntity::getUserId,pUserId);
        remove(queryWrapper);
    }

}
